home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / SCRIPT.PAK / ED_CLSSC.SPP < prev    next >
Text File  |  1997-05-06  |  16KB  |  663 lines

  1. //----------------------------------------------------------------------------
  2. // cScript
  3. // (C) Copyright 1995, 1997 by Borland International, All Rights Reserved
  4. //
  5. // ED_CLSSC.SPP
  6. //    Script component of IDE's Editor Classic emulation.
  7. //    Provides support services for editing environment.
  8. //
  9. // $Revision:   1.8  $
  10. //
  11. //----------------------------------------------------------------------------
  12. // Classic Editor.
  13. //----------------------------------------------------------------------------
  14.  
  15. //----------------------------------------------------------------------------
  16. // Symbol Imports
  17. //----------------------------------------------------------------------------
  18.  
  19. import IDE;
  20. import editor;
  21. import scriptEngine;
  22. import bFileLoading;
  23.  
  24. //
  25. // Mark this module as being a library module.
  26. //
  27. library;
  28.  
  29. //----------------------------------------------------------------------------
  30. // Symbol Defines
  31. //----------------------------------------------------------------------------
  32.  
  33. #define BOOKMARK_ID_SYSTEM_ONE   19
  34. #define BOOKMARK_ID_SYSTEM_TWO   18
  35. #define BOOKMARK_ID_SYSTEM_THREE 17
  36. #define FUNCTION_CONTINUE 0
  37. #define FUNCTION_END      1
  38.  
  39. //----------------------------------------------------------------------------
  40. // Menu Vectors.
  41. //----------------------------------------------------------------------------
  42.  
  43. DoIDEFileClose()      { return FUNCTION_CONTINUE; }
  44. DoIDEFileOpen()       { return FUNCTION_CONTINUE; }
  45. DoIDEFilePrint()      { return FUNCTION_CONTINUE; }
  46. DoIDEFileSave()       { return FUNCTION_CONTINUE; }
  47. DoIDEFileSaveAs()     { return FUNCTION_CONTINUE; }
  48. DoIDEFileSaveAll()    { return FUNCTION_CONTINUE; }
  49.  
  50. DoIDEEditUndo()       { editor.Undo(); return FUNCTION_END; }
  51. DoIDEEditRedo()       { editor.Redo(); return FUNCTION_END; }
  52. DoIDEEditCut()        { editor.ClassicCut(); return FUNCTION_END; }
  53. DoIDEEditCopy()       { editor.Copy(); return FUNCTION_END;  }
  54. DoIDEEditPaste()      { editor.Paste(); return FUNCTION_END; }
  55. DoIDEEditClear()      { editor.ClassicBlockDelete(); return FUNCTION_END; }
  56. DoIDEEditSelectAll()  { editor.SelectAll(); return FUNCTION_END; }
  57. DoIDEEditBufferList() { return FUNCTION_CONTINUE; }
  58.  
  59. DoIDESearchFind()     { editor.Search(); return FUNCTION_CONTINUE; }
  60. DoIDESearchReplace()  { editor.Replace(); return FUNCTION_CONTINUE; }
  61. DoIDESearchSearchAgain() { return FUNCTION_CONTINUE; }
  62.  
  63. DoIDESearchPreviousMessage() { return FUNCTION_CONTINUE; }
  64. DoIDESearchNextMessage()     { return FUNCTION_CONTINUE; }
  65.  
  66. //----------------------------------------------------------------------------
  67. // Methods.
  68. //----------------------------------------------------------------------------
  69.  
  70. //
  71. // Used to autoload the Default emulation specific methods.
  72. //
  73. classicEmulation(bUnassign) {
  74.  
  75.    IDE.KeyboardManager.ScriptAbortKey = "<Escape>";
  76.    IDE.KeyboardManager.ProcessKeyboardAssignments(scriptEngine.StartupDirectory+IDE.KeyboardAssignmentFile,bUnassign);
  77.    
  78.    if (bUnassign) {
  79.       print "Classic emulation removed.";
  80.       scriptEngine.Unload(typeid(module()));
  81.    } else {
  82.       print "Classic emulation enabled.";
  83.    }
  84. }
  85.  
  86. //----------------------------------------------------------------------------
  87. // Classic Editor.
  88. //----------------------------------------------------------------------------
  89.  
  90. //
  91. // Delete the current block.
  92. //
  93. on editor:>ClassicBlockDelete() {
  94.    declare eb = .BlockExists();
  95.    if (eb != NULL) {
  96.       .ClassicDelete();
  97.       IDE.StatusBar = "Block deleted";
  98.    }
  99. }
  100.  
  101. //
  102. // Using Classic behavior perform block copy operation.
  103. //
  104. on editor:>ClassicCopyBlock() {
  105.       declare eb = .BlockExists();
  106.    if (eb != NULL) {
  107.       eb.Copy();
  108.       .TopView.Position.InsertScrap();
  109.       IDE.StatusBar = "Block copied";
  110.    } else
  111.       IDE.ReportError("No marked block");
  112. }
  113.  
  114. //
  115. // Delete the current block.
  116. //
  117. on editor:>ClassicCut() {
  118.    declare eb = .BlockExists();
  119.    if (eb != NULL) {
  120.       declare ev = .TopView;
  121.       ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_ONE);
  122.       eb.Cut();
  123.       ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
  124.    }
  125. }
  126.  
  127. //
  128. // Delete the current block.
  129. //
  130. on editor:>ClassicDelete() {
  131.    declare eb = .BlockExists();
  132.    if (eb != NULL) {
  133.       declare ev = .TopView;
  134.       ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_ONE);
  135.       eb.Delete();
  136.       ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
  137.    }
  138. }
  139.  
  140. //
  141. // Uses Classic specific behavior to delete a line.
  142. //
  143. on editor:>ClassicDeleteLine() {
  144.  
  145.    declare bBlock = FALSE;
  146.    declare eb = .BlockExists();
  147.    declare ev = .TopView;
  148.    declare ep = ev.Position;
  149.  
  150.    if (eb != NULL) {
  151.       eb.Save();
  152.       ep.Save();
  153.       ep.Move(eb.StartingRow,eb.StartingColumn);
  154.       ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_ONE);
  155.       ep.Move(eb.EndingRow,eb.EndingColumn);
  156.       ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_TWO);
  157.       ep.Restore();
  158.       eb.Restore();
  159.       bBlock = TRUE;
  160.    } else
  161.       eb = .TopView.Block;
  162.  
  163.    declare ebs = eb.Style;
  164.    ep.MoveBOL();
  165.    ep.Save();
  166.    BeginBlock(LINE_BLOCK);
  167.    eb.Delete();
  168.    ep.Restore();
  169.  
  170.    SetBlockStyle(ebs);
  171.  
  172.    if (bBlock) {
  173.       ep.Save();
  174.       ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
  175.       eb.Begin();
  176.       ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_TWO);
  177.       eb.End();
  178.       ep.Restore();
  179.    }
  180. }
  181.  
  182. //
  183. // Uses Classic specific behavior for deletion of the current word.
  184. //
  185. on editor:>ClassicDeleteToEOL() {
  186.    declare rv = "";
  187.    declare ep = .TopView.Position;
  188.    declare eb = .BlockExists();
  189.  
  190.    if (eb == NULL)
  191.       eb = .TopView.Block;
  192.  
  193.    eb.Save();
  194.  
  195.    ep.Save();
  196.    ep.MoveEOL();
  197.    declare nEndRow = ep.Row;
  198.    declare nEndCol = ep.Column;
  199.    ep.Restore();
  200.    ep.Save();
  201.  
  202.    declare nColumnCorrection = .TopView.LeftColumn;
  203.  
  204.    // see if we are already at (or past) the end
  205.    if (ep.Column <= nEndCol) {
  206.       ResetBlock();
  207.       BeginBlock(EXCLUSIVE_BLOCK);
  208.       eb.Extend(nEndRow, nEndCol);
  209.       rv = eb.Text;
  210.       eb.Delete();
  211.    }
  212.  
  213.    ep.Restore();
  214.    eb.Restore();
  215.  
  216.  
  217.    if (nColumnCorrection != .TopView.LeftColumn) {
  218.       .TopView.Scroll(0, (.TopView.LeftColumn - nColumnCorrection) * -1 );
  219.    }
  220.  
  221.    return rv;
  222. }
  223.  
  224. on editor:>ClassicDeleteWordLeft() {
  225.  
  226.    declare nBlocked = FALSE;
  227.    declare eb = .BlockExists();
  228.    declare ev = .TopView;
  229.    declare ep = ev.Position;
  230.  
  231.    if (eb != NULL) {
  232.       eb.Save();
  233.       ep.Save();
  234.       ep.Move(eb.StartingRow,eb.StartingColumn);
  235.       ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_ONE);
  236.       ep.Move(eb.EndingRow,eb.EndingColumn);
  237.       ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_TWO);
  238.       ep.Restore();
  239.       eb.Restore();
  240.       nBlocked = TRUE;
  241.    }
  242.  
  243.    eb = ResetBlock(EXCLUSIVE_BLOCK);
  244.    eb.End();
  245.  
  246.    ep.MoveCursor(SKIP_LEFT | SKIP_NONWORD);
  247.    ep.MoveCursor(SKIP_LEFT | SKIP_WORD);
  248.  
  249.    eb.Begin();
  250.  
  251.    eb.Cut();
  252.  
  253.    if (nBlocked) {
  254.       SetBlockStyle(EXCLUSIVE_BLOCK);
  255.       ep.Save();
  256.       ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
  257.       eb.Begin();
  258.       ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_TWO);
  259.       eb.End();
  260.       ep.Restore();
  261.    }
  262. }
  263.  
  264. on editor:>ClassicDeleteWordRight() {
  265.  
  266.    declare nBlocked = FALSE;
  267.    declare eb = .BlockExists();
  268.    declare ev = .TopView;
  269.    declare ep = ev.Position;
  270.  
  271.    if (eb != NULL) {
  272.       eb.Save();
  273.       ep.Save();
  274.       ep.Move(eb.StartingRow,eb.StartingColumn);
  275.       ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_ONE);
  276.       ep.Move(eb.EndingRow,eb.EndingColumn);
  277.       ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_TWO);
  278.       ep.Restore();
  279.       eb.Restore();
  280.       nBlocked = TRUE;
  281.    }
  282.  
  283.    eb = ResetBlock(EXCLUSIVE_BLOCK);
  284.    eb.Begin();
  285.  
  286.    declare nSpaceAdjust = 0;
  287.    ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_THREE);
  288.  
  289.    if (ep.IsWhiteSpace) {
  290.  
  291.       if (ep.Character == '\t') {
  292.           declare c = ep.Column;
  293.           ep.Delete(1);
  294.           if (ep.Column != c)
  295.              nSpaceAdjust = c - ep.Column;
  296.       }
  297.       ep.MoveCursor(SKIP_RIGHT | SKIP_WHITE);
  298.    } else if (ep.IsWordCharacter) {
  299.       ep.MoveCursor(SKIP_RIGHT | SKIP_WORD);
  300.       ep.MoveCursor(SKIP_RIGHT | SKIP_WHITE);
  301.    } else if (ep.IsSpecialCharacter) {
  302.       ep.Delete(1);
  303.       ep.MoveCursor(SKIP_RIGHT | SKIP_WHITE);
  304.    } else
  305.       ep.Delete(1);
  306.  
  307.    eb.End();
  308.    eb.Delete();
  309.  
  310.    ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_THREE);
  311.  
  312.    while (nSpaceAdjust--) {
  313.       ep.InsertText(' ');
  314.    }
  315.  
  316.    if (nBlocked) {
  317.       SetBlockStyle(EXCLUSIVE_BLOCK);
  318.       ep.Save();
  319.       ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
  320.       eb.Begin();
  321.       ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_TWO);
  322.       eb.End();
  323.       ep.Restore();
  324.    }
  325. }
  326.  
  327. //
  328. // Uses Classic specific behavior to mark a line.
  329. //
  330. on editor:>ClassicMarkLine() {
  331.  
  332.    declare ep = .TopView.Position;
  333.  
  334.    ep.Save();
  335.    ep.Move(0,1);
  336.    BeginBlock(EXCLUSIVE_BLOCK);
  337.    ep.MoveRelative(1,0);
  338.    EndBlock(EXCLUSIVE_BLOCK);
  339.    ep.Restore();
  340. }
  341.  
  342. //
  343. // Using Classic behaviour marks and returns the current word.
  344. //
  345. on editor:>ClassicMarkWord() {
  346.    declare ep = .TopView.Position;
  347.  
  348.    if (!.TopView.Position.IsWordCharacter) {
  349.       .MoveCursorToWordLeft();
  350.    }
  351.  
  352.    return .MarkWord();
  353. }
  354. //
  355. // Uses Classic specific behavior to lowercase current word.
  356. //
  357. on editor:>ClassicLowerWord(declare bUseCurrentBlock) {
  358.  
  359.    declare bBlock = FALSE;
  360.    declare eb = .BlockExists();
  361.  
  362.    if (eb != NULL) {
  363.       bBlock = TRUE;
  364.       eb.Save();
  365.    }
  366.  
  367.    .TopView.BookmarkRecord(BOOKMARK_ID_SYSTEM_ONE);
  368.    .MarkWord().LowerCase();
  369.    .TopView.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
  370.    .TopView.Block.Reset();
  371.  
  372.    if (bBlock) {
  373.       eb.Restore();
  374.    }
  375. }
  376.  
  377.  
  378. //
  379. // Uses Classic specific behavior to mark to the top of the view.
  380. //
  381. on editor:>ClassicMarkToViewTop() {
  382.    declare ev = .TopView;
  383.    declare eb = ev.Block;
  384.    declare ep = ev.Position;
  385.  
  386.    if ((eb.StartingRow == ep.Row) && (eb.StartingColumn == ep.Column)) {
  387.       SetBlockStyle(EXCLUSIVE_BLOCK);
  388.       ep.Move(eb.EndingRow,eb.EndingColumn);
  389.       eb.End();
  390.       eb.Extend(ev.TopRow, ev.Position.Column);
  391.       eb.Begin();
  392.    } else {
  393.       ResetBlock(EXCLUSIVE_BLOCK);
  394.       eb.End();
  395.       eb.Extend(ev.TopRow, ev.Position.Column);
  396.       eb.Begin();
  397.    }
  398. }
  399.  
  400. //
  401. // Uses Classic specific behavior to mark to the end of the view.
  402. //
  403. on editor:>ClassicMarkToViewBottom() {
  404.    declare ev = .TopView;
  405.    declare eb = ev.Block;
  406.    declare ep = ev.Position;
  407.    if ((eb.EndingRow == ep.Row) && (eb.EndingColumn == ep.Column)) {
  408.       SetBlockStyle(EXCLUSIVE_BLOCK);
  409.       ep.Move(eb.StartingRow,eb.StartingColumn);
  410.       eb.Begin();
  411.       eb.Extend(ev.BottomRow-1, ev.Position.Column);
  412.       eb.End();
  413.    } else {
  414.       eb.Reset();
  415.       SetBlockStyle(EXCLUSIVE_BLOCK);
  416.       eb.Begin();
  417.       eb.Extend(ev.BottomRow-1, ev.Position.Column);
  418.       eb.End();
  419.    }
  420. }
  421.  
  422. //
  423. // Uses Classic specific behavior to mark to the end of the line.
  424. //
  425. on editor:>ClassicMarkToEOL() {
  426.    declare eb = .BlockExists();
  427.     
  428.    if (eb == NULL)
  429.       ResetBlock();
  430.  
  431.   .MarkToEOL();
  432. }
  433.  
  434. //
  435. // Uses Classic specific behavior to mark to the begining of the line.
  436. //
  437. on editor:>ClassicMarkToBOL() {
  438.    declare eb = .BlockExists();
  439.     
  440.    if (eb == NULL)
  441.       ResetBlock();
  442.  
  443.   .MarkToBOL();
  444. }
  445.  
  446. //
  447. // Uses Classic specific behavior to mark to the begining of the file.
  448. //
  449. on editor:>ClassicMarkToBOF() {
  450.    declare eb = .TopView.Block;
  451.    declare ep = .TopView.Position;
  452.    if ((eb.StartingRow == ep.Row) && (eb.StartingColumn == ep.Column)) {
  453.       SetBlockStyle(EXCLUSIVE_BLOCK);
  454.       ep.Move(eb.EndingRow,eb.EndingColumn);
  455.       eb.End();
  456.       ep.Move(1,1);
  457.       eb.Begin();
  458.    } else {
  459.       eb.Reset();
  460.       SetBlockStyle(EXCLUSIVE_BLOCK);
  461.       eb.End();
  462.       ep.Move(1,1);
  463.       eb.Begin();
  464.    }
  465. }
  466.  
  467. //
  468. // Uses Classic specific behavior to mark to the end of the file.
  469. //
  470. on editor:>ClassicMarkToEOF() {
  471.    declare eb = .TopView.Block;
  472.    declare ep = .TopView.Position;
  473.    if ((eb.EndingRow == ep.Row) && (eb.EndingColumn == ep.Column)) {
  474.       SetBlockStyle(EXCLUSIVE_BLOCK);
  475.       ep.Move(eb.StartingRow,eb.StartingColumn);
  476.       eb.Begin();
  477.       ep.MoveEOF();
  478.       eb.End();
  479.    } else {
  480.       eb.Reset();
  481.       SetBlockStyle(EXCLUSIVE_BLOCK);
  482.       eb.Begin();
  483.       ep.MoveEOF();
  484.       eb.End();
  485.    }
  486. }
  487.  
  488. //
  489. // Uses Classic specific behavior to toggle current character.
  490. //
  491. on editor:>ClassicToggleCase() {
  492.  
  493.    declare bBlock = FALSE;
  494.    declare eb = .BlockExists();
  495.    declare ep = .TopView.Position;
  496.  
  497.    if (eb != NULL) {
  498.        bBlock = TRUE;
  499.        eb.Save();
  500.    } else
  501.        eb = .TopView.Block;
  502.  
  503.    if ((ep.Column <= eb.EndingColumn && ep.Row <= eb.EndingRow) &&
  504.        (ep.Column >= eb.StartingColumn && ep.Row >= eb.StartingRow))
  505.        eb.ToggleCase();
  506.    else {           
  507.      eb.Begin();
  508.      ep.MoveRelative(0,1);
  509.      eb.End();
  510.      eb.ToggleCase();
  511.      eb.Reset();
  512.    }   
  513.  
  514.    if (bBlock) {
  515.       eb.Restore();
  516.    }
  517.  
  518. }
  519.  
  520. //
  521. // Uses Classic specific behavior to move current block to cursor
  522. // position.
  523. //
  524. on editor:>ClassicMoveBlock() {
  525.    declare eb = .BlockExists();
  526.    if (eb != NULL) {
  527.       declare ev = .TopView;
  528.       declare ep = ev.Position;
  529.       ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_ONE);
  530.       eb.Save();
  531.       ep.Move(eb.StartingRow, eb.StartingColumn);
  532.       eb.Restore();
  533.       eb.Cut();
  534.       ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
  535.       declare nRow = ep.Row;
  536.       declare nColumn = ep.Column;
  537.       ep.InsertScrap();
  538.       ep.Move(nRow, nColumn);
  539.       eb.Begin();
  540.       ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
  541.       eb.Extend(ep.Row, ep.Column);
  542.       eb.Save();
  543.       ep.Move(nRow, nColumn);
  544.       eb.Restore();
  545.       IDE.StatusBar = "Block moved";
  546.    } else {
  547.       IDE.ReportError("No marked block");
  548.    }
  549. }
  550.  
  551.  
  552. //
  553. // Read file into current buffer.
  554. //
  555. on editor:>ClassicReadFileIntoBuffer() {
  556.  
  557.    declare sFileName = new 
  558.       String(ContextSensitiveFileDialog("EditFile", "File to read:", "*.*"));
  559.  
  560.    if (sFileName.Text != "" && IDE.IsLegalFileName(sFileName.Text)) {
  561.       .TopView.Position.Save();
  562.       .TopView.Position.InsertFile(sFileName.Text);
  563.       .TopView.Position.Restore();
  564.       IDE.StatusBar = "File Read.";
  565.    }
  566. }
  567.  
  568. //
  569. // Start block at current position.
  570. //
  571. on editor:>ClassicStartBlock(declare type) {
  572.      declare eb = .BlockExists();
  573.      declare ep = .TopView.Position;
  574.  
  575.      if (eb != NULL) {
  576.          declare ev = .TopView;
  577.          declare tr = ev.TopRow;
  578.          declare lc = ev.LeftColumn;
  579.          declare er = eb.EndingRow;
  580.          declare ec = eb.EndingColumn;
  581.          declare epr = ep.Row;
  582.          declare epc = ep.Column;
  583.  
  584.  
  585.          if (epr == er) {
  586.              if (epc >= ec) {
  587.                  ec = epc;
  588.              }
  589.          }
  590.  
  591.          if (epr > er) {
  592.              er = epr;
  593.          }
  594.  
  595.          ep.Save();
  596.          BeginBlock(type);
  597.          ep.Move(er,ec);
  598.          EndBlock(type);
  599.          ep.Restore();
  600.          ev.SetTopLeft(tr,lc);
  601.      } else {
  602.          BeginBlock(type);
  603.      }
  604. }
  605.  
  606. //
  607. // End block at current position.
  608. //
  609. on editor:>ClassicStopBlock(declare type) {
  610.      declare eb = .BlockExists();
  611.      declare ep = .TopView.Position;
  612.  
  613.      if (eb != NULL) {
  614.          declare sr = eb.StartingRow;
  615.          declare sc = eb.StartingColumn;
  616.          declare epr = ep.Row;
  617.          declare epc = ep.Column;
  618.  
  619.  
  620.          if (epr == sr) {
  621.              if (epc <= sc) {
  622.                  sc = epc;
  623.              }
  624.          }
  625.  
  626.          if (epr < sr) {
  627.              sr = epr;
  628.          }
  629.  
  630.          ep.Save();
  631.          ep.Move(sr,sc);
  632.          BeginBlock(type);
  633.          ep.Restore();
  634.      }
  635.  
  636.      EndBlock(type);
  637. }
  638.  
  639. //
  640. // Uses Classic specific behavior to uppercase current word.
  641. //
  642. on editor:>ClassicUpperWord() {
  643.  
  644.    declare bBlock = FALSE;
  645.    declare eb = .BlockExists();
  646.  
  647.    if (eb != NULL) {
  648.       bBlock = TRUE;
  649.       eb.Save();
  650.    }
  651.  
  652.    .TopView.BookmarkRecord(BOOKMARK_ID_SYSTEM_ONE);
  653.    .MarkWord().UpperCase();
  654.    .TopView.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
  655.    .TopView.Block.Reset();
  656.  
  657.    if (bBlock) {
  658.       eb.Restore();
  659.    }
  660. }
  661.  
  662.  
  663.